package com.thinkgem.jeesite.modules.sys.utils;

import com.google.common.collect.Lists;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.SpringContextHolder;
import com.thinkgem.jeesite.modules.act.entity.Act;
import com.thinkgem.jeesite.modules.act.service.ActTaskService;
import com.thinkgem.jeesite.modules.oa.dao.OaNewsDao;
import com.thinkgem.jeesite.modules.oa.dao.OaScheduleDao;
import com.thinkgem.jeesite.modules.oa.entity.OaNews;
import com.thinkgem.jeesite.modules.oa.entity.OaSchedule;
import com.thinkgem.jeesite.modules.sys.dao.UserDao;
import com.thinkgem.jeesite.modules.sys.entity.User;
import org.springframework.ui.Model;

import java.util.*;

/**
 * Created by lgx on 2016/11/18.
 */
public class NoticeUnits {

    private static OaNewsDao newsDao = SpringContextHolder.getBean(OaNewsDao.class);

    private static ActTaskService actTaskService = SpringContextHolder.getBean(ActTaskService.class);

    private static UserDao userDao = SpringContextHolder.getBean(UserDao.class);

    private static OaScheduleDao scheduleDao = SpringContextHolder.getBean(OaScheduleDao.class);



    /**
     * 获取当前用户可审核的新闻公告
     * @return
     */
    public static List<OaNews> getAuditNews(){
        User user = UserUtils.getUser();
        if(user != null){
            OaNews news = new OaNews();
            news.setAuditMan(user.getId());
            news.setAuditFlag("0");
            String companyid=  UserUtils.getUser().getCompany().getId();
            // news.setCompanyId(companyid);

            //以前的新闻公告审核（查出俩条的）
            //List<OaNews> newsList = newsDao.findListAndRole(news);
            List<OaNews> newsList = newsDao.findList(news);
            if(newsList == null){
                newsList = Lists.newArrayList();
            }
            return newsList;
        }
        return Lists.newArrayList();
    }

    /**
     * 获取待办列表
     * @return
     */
    public static List<Act> getTodo(){
        String userId="";
        List<Act> acts = actTaskService.todoList(new Act(),userId);
        if(acts == null){
            acts = Lists.newArrayList();
        }
        return acts;
    }

    /**
     * 获取当前用户可审核的新闻公告
     * @return
     */
    public static List<OaNews> getAllNews(){
        OaNews news = new OaNews();
        news.setAuditFlag("1");
        news.setSelf(true);
      String companyid=  UserUtils.getUser().getCompany().getId();
     news.setCompanyId(companyid);
        List<OaNews> newsList = newsDao.findList(news);
        if(newsList == null){
            newsList = Lists.newArrayList();
        }
        return newsList;
    }


    /**
     * 获取所有已发布新闻公告并查询关联的角色和用户信息
     * @return
     */
    public static List<OaNews> getFifteenNewsAndRole(){
        OaNews news = new OaNews();
        news.setAuditFlag("1");
        news.setSelf(true);
        List<OaNews> newsList = newsDao.findListAndRole(news);
        if(newsList == null){
            newsList = Lists.newArrayList();
        }
        return newsList;
    }

    /**
     * 获取所有已发布新闻公告并查询关联的角色和用户信息
     * @return
     */
    public static List<OaNews> getAllNewsAndRole(){
        OaNews news = new OaNews();
        news.setAuditFlag("1");
        news.setSelf(true);
        List<OaNews> newsList = newsDao.findList(news);
        if(newsList == null){
            newsList = Lists.newArrayList();
        }
        return newsList;
    }

    //根据用户id查询新闻公告
    public static List<OaNews> getAllCollectNews(){
        OaNews news = new OaNews();
        news.setAuditFlag("1");

        List<OaNews> newsList = newsDao.findCollectList(news);
        if(newsList == null){
            newsList = Lists.newArrayList();
        }
        return newsList;
    }


    //根据用户id查询当日日程
    public static List<OaSchedule> getOaSchedule(){
        OaSchedule schedule = new OaSchedule();
        schedule.setFlag("0");
        schedule.setLoginId(UserUtils.getUser().getId());


        Calendar currentDate = new GregorianCalendar();

        currentDate.set(Calendar.HOUR_OF_DAY, 0);
        currentDate.set(Calendar.MINUTE, 0);
        currentDate.set(Calendar.SECOND, 0);
        schedule.setScheduleDate((Date)currentDate.getTime().clone());




        List<OaSchedule> scheduleList = scheduleDao.findOaSchedule(schedule);
        if(scheduleList == null){
            scheduleList = Lists.newArrayList();
        }
        return scheduleList;
    }
}
